package cn.haocxy.jfm.gui.dialog;

import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;

public class ConfirmDialog extends Dialog {

	private Text text;
	
	private Button ok;
	
	private Button cancel;
	
	private boolean isOK = false;
	
	@Override
	protected void setContentArea(AnchorPane pane) {
		text = new Text();
		pane.getChildren().add(text);
		AnchorPane.setTopAnchor(text, 10.0);
		AnchorPane.setLeftAnchor(text, 10.0);
		AnchorPane.setRightAnchor(text, 10.0);
	}

	public ConfirmDialog setText(String text) {
		this.text.setText(text);
		return this;
	}
	
	public boolean ok() {
		return isOK;
	}
	
	public boolean canceled() {
		return !isOK;
	}
	
	@Override
	protected void setButtons() {
		this.add(ok = new DButton("确认"));
		this.add(cancel = new DButton("取消"));
		
		ok.setOnAction(e->{
			isOK = true;
			hide();
		});
		
		cancel.setOnAction(e->{
			isOK = false;
			hide();
		});
	}

	@Override
	protected void onShowing() {
	}

	@Override
	protected void onHiding() {
	}

}
